<?php


$src = '111.png';
//thumb($src);
//压缩图片
function thumb($src)
{
	$imagestr = file_get_contents($src);
	$image = imagecreatefromstring($imagestr);
	list($x,$y) = getimagesize($src);
	
	$dst_image = imagecreatetruecolor($x/2,$y/2);//压缩图片
	imagecopyresized($dst_image, $image, 0, 0, 0, 0, $x/2, $y/2, $x, $y);
	$leng = strripos($src,'.');
	$leng++;
	$suffix = substr($src,$leng);
	$filename = time().mt_rand(10000,99999);
	switch($suffix)
	{
		case 'jpg':imagejpeg($dst_image,$filename.'.jpg');break;
		case 'png':imagejpeg($dst_image,$filename.'.png');break;
		case 'bmp':imagejpeg($dst_image,$filename.'.bmp');break;
		case 'gif':imagejpeg($dst_image,$filename.'.gif');break;
	}
	return $filename;
}

//waterstr('1.jpg');
//文字水印
function waterstr($src)
{
	$imagestr = file_get_contents($src);
	$image = imagecreatefromstring($imagestr);
	$waterstr = '1111';
	$color = imagecolorallocate($image,255,255,255);//三原色
	imagefttext($image, 80, 0, 100, 100, $color, 'ACASLONPRO-BOLD.OTF',$waterstr);
	
	$leng = strripos($src,'.');
	$leng++;
	$suffix = substr($src,$leng);
	$filename = time().mt_rand(10000,99999);
	switch($suffix)
	{
		case 'jpg':imagejpeg($image,$filename.'.jpg');break;
		case 'png':imagejpeg($image,$filename.'.png');break;
		case 'bmp':imagejpeg($image,$filename.'.bmp');break;
		case 'gif':imagejpeg($image,$filename.'.gif');break;
	}
	return $filename;	
}
//imagewater('111.png','1.jpg');

//图片水印
function imagewater($src,$dst)
{
	list($src_w,$src_h) = getimagesize($src);//获取图片尺寸
	//获取目的文件后缀名
	$leng = strripos($dst,'.');
	$leng++;
	$suffix = substr($dst,$leng);
	//获取源文件也就是水印文件的资源
	$src = file_get_contents($src);//将某个文件读取成字符串 
	$src = imagecreatefromstring($src);//将字符串转换成图片
	//回去目的文件资源
	$dst = file_get_contents($dst);
	$dst = imagecreatefromstring($dst);
	//生成图片
	imagecopymerge($dst, $src, 0, 0, 0, 0, $src_w, $src_h, 100);//生成图片水印
	
	$filename = time().mt_rand(10000,99999);
	switch($suffix)
	{
		case 'jpg':imagejpeg($dst,$filename.'.jpg');break;
		case 'jpeg':imagejpeg($dst,$filename.'.jpg');break;
		case 'png':imagejpeg($dst,$filename.'.png');break;
		case 'bmp':imagejpeg($dst,$filename.'.bmp');break;
		case 'gif':imagejpeg($dst,$filename.'.gif');break;
	}
	return $filename;
}







?>